package ${basePackageName}.dao ;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import e.odbo.data.dao.BaseDAO;

import ${basePackageName}+.bean.+${className};

<#list importBeanClass as importClass>
import ${importClass};
</#list>

public class ${className}DAO extends BaseDAO<${className}> {

    public ${className}DAO(I_Session s) {
    super(s);
    }

    @Override
    public TableDefinition getTable() {
    return new TableDefinition(
    "${tableName}",
    new Field[]{

<#list columns as column>
    <#if column_index!=columns?size>
            new Field("${column.value}",Datas.${column.columnType},Formats.${column.columnType} <#if column.refClassName??>,"${column.refClassName}".class</#if>),
    <#else>
             new Field("${column.value}",Datas.${column.columnType},Formats.${column.columnType}<#if column.refClassName??>,"${column.refClassName}".class</#if>)
    </#if>

</#list>
    },
    new int[]{${idIndex}});
    }

    @Override
    public AppLoger readValues(DataRead dr,AppLoger obj) throws BasicException {
    if(obj==null)
       obj=new ${className}();

<#list columns as column>
       obj.set${column.propertyName?cap_first} (dr.get${column.propertyType}(${column_index}));

</#list>

    return obj;
    }

    @Override
    public void writeInsertValues(DataWrite dp, AppLoger obj)
    throws BasicException {
<#list columns as column>
        dr.set${column.propertyType}(${column_index},obj.get${column.propertyName?cap_first}());
</#list>
    }

    @Override
    public Class getSuportClass() {
      return ${className}.class;
    }
}
